import Vue from 'vue'
import Router from 'vue-router'
import store from '@/store/index'

import { MessageBox } from 'element-ui'

import { getToken } from '@/utils/auth'
import { basicRouter } from './basicRouter'

Vue.use(Router)

const router = new Router({
  mode: 'history',
  scrollBehavior: () => ({ y: 0 }),
  routes: basicRouter
})


router.beforeEach((to, from, next) => {
  next() // 跳过登录验证
  // if (getToken()) {
  //   /* has token */
  //   if (store.getters.userId === '') {
  //     // 判断当前用户是否已拉取完user_info信息
  //     store.dispatch('GetInfo').then(() => {
  //       // 拉取user_info
  //       next({ ...to, replace: true })
  //     }).catch(() => {
  //       store.dispatch('LogOut').then(() => {
  //         window.location.href = '/'
  //       })
  //     })
  //   } else {
  //     next()
  //   }
  // } else {
  //   MessageBox.confirm('用户尚未登录, 请重新登录', '系统提示', {
  //     confirmButtonText: '重新登录',
  //     cancelButtonText: '取消',
  //     type: 'warning'
  //   }).then(() => {
  //     store.dispatch('LogOut').then(() => {
  //       window.location.href = '/'
  //     })
  //   })
  // }
})


export default router
